using System.Web.Mvc;
using OurWedding1.Models;

namespace OurWedding1.Controllers
{   
    [Authorize]
    public class HomePageParagraphsController : Controller
    {
		private readonly IHomePageParagraphRepository _homepageparagraphRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public HomePageParagraphsController() : this(new HomePageParagraphRepository())
        {
        }

        public HomePageParagraphsController(IHomePageParagraphRepository homepageparagraphRepository)
        {
			_homepageparagraphRepository = homepageparagraphRepository;
        }

        //
        // GET: /HomePageParagraphs/

        public ViewResult Index()
        {
            return View(_homepageparagraphRepository.All);
        }

        //
        // GET: /HomePageParagraphs/Details/5

        public ViewResult Details(int id)
        {
            return View(_homepageparagraphRepository.Find(id));
        }

        //
        // GET: /HomePageParagraphs/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /HomePageParagraphs/Create

        [HttpPost]
        public ActionResult Create(HomePageParagraph homepageparagraph)
        {
            if (ModelState.IsValid) {
                _homepageparagraphRepository.InsertOrUpdate(homepageparagraph);
                _homepageparagraphRepository.Save();
                return RedirectToAction("Index");
            }
            return View();
        }

        //
        // GET: /HomePageParagraphs/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(_homepageparagraphRepository.Find(id));
        }

        //
        // POST: /HomePageParagraphs/Edit/5

        [HttpPost]
        public ActionResult Edit(HomePageParagraph homepageparagraph)
        {
            if (ModelState.IsValid) {
                _homepageparagraphRepository.InsertOrUpdate(homepageparagraph);
                _homepageparagraphRepository.Save();
                return RedirectToAction("Index");
            }
            return View();
        }

        //
        // GET: /HomePageParagraphs/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(_homepageparagraphRepository.Find(id));
        }

        //
        // POST: /HomePageParagraphs/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            _homepageparagraphRepository.Delete(id);
            _homepageparagraphRepository.Save();

            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                _homepageparagraphRepository.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

